package com.budwk.app.sqfw.services.customservice.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSONObject;
import com.budwk.app.common.config.AppException;
import com.budwk.app.sqfw.component.CommunityStreetComponent;
import com.budwk.app.sqfw.constants.CommonConstants;
import com.budwk.app.sqfw.models.Sqfw_cenSusPaper;
import com.budwk.app.sqfw.models.Sqfw_completeflow;
import com.budwk.app.sqfw.models.Sqfw_formSummary_new;
import com.budwk.app.sqfw.services.SqfwCompleteflowService;
import com.budwk.app.sqfw.services.SqfwFormsummaryNewService;
import com.budwk.app.sqfw.services.common.SqfwCommonForAdminService;
import com.budwk.app.sqfw.services.common.SqfwCustomForAdminCommonService;
import com.budwk.app.sqfw.services.impl.SqfwSummaryForAdminServiceImpl;
import com.budwk.app.sqfw.vo.CheckDataForAdminVO;
import com.budwk.app.sqfw.vo.GenerateExcelUrlVO;
import com.budwk.app.sqfw.vo.GenerateWordAndPdfUrlVO;
import com.budwk.app.sqfw.vo.SqfwCustomForAdminCommonVO;
import com.budwk.app.sqfwDoc.bo.ExcelCreateConfig;
import com.budwk.app.sqfwDoc.codeGeneratorV2.generate.ResultOfExcelGenerator;
import com.budwk.app.sqfwV2.enums.EducationalInstitutionEnums;
import com.budwk.app.sqfwV2.enums.weiqingmen.SafetyCheckEnum;
import com.budwk.app.sqfwV2.service.weiqingmen.SafetyCheckExcelService;
import com.budwk.app.sqfwV2.service.weiqingmen.SafetyCheckPdfService;
import com.budwk.app.sys.models.Sys_user;
import com.budwk.app.sys.services.SysLogService;
import com.budwk.app.sys.services.SysUserService;
import com.budwk.app.util.adminUtils.CommonCheckUtils;
import com.budwk.app.util.poiUtils.CommonFormOfficeForAdminUtils;
import com.budwk.app.util.poiUtils.CommonFormOfficeUtils;
import com.budwk.starter.common.page.Pagination;
import com.budwk.starter.common.result.ResultCode;
import com.budwk.starter.security.utils.SecurityUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.ObjectUtils;
import org.nutz.aop.interceptor.ioc.TransAop;
import org.nutz.dao.Cnd;
import org.nutz.dao.entity.annotation.Table;
import org.nutz.dao.sql.Criteria;
import org.nutz.dao.util.cri.SqlExpressionGroup;
import org.nutz.dao.util.cri.Static;
import org.nutz.ioc.aop.Aop;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.lang.Strings;

import java.util.*;
import java.util.stream.Collectors;

/**
 * @program: dfxy-community
 * @description: 威清门安全排查（后台管理）
 * @author: LJT
 * @create: 2024-05-10 09:04
 **/
@IocBean(name = "WeiQingMenSecurityForAdminService")
@Slf4j
public class WeiQingMenSecurityForAdminServiceImpl extends SafetyCheckExcelService implements SqfwCustomForAdminCommonService {

    @Inject
    private CommunityStreetComponent communityStreetComponent;

    @Inject
    private SqfwFormsummaryNewService sqfwFormsummaryNewService1;

    @Inject
    private SqfwCompleteflowService sqfwCompleteflowService;

    @Inject
    private SysLogService sysLogService;

    @Inject
    private SysUserService sysUserService;

    @Inject
    private SafetyCheckPdfService safetyCheckPdfService;

    @Inject
    private SqfwCommonForAdminService sqfwCommonForAdminService;

    @Override
    public Pagination list(SqfwCustomForAdminCommonVO bean) {
        if (StringUtils.isEmpty(bean.getType())) {
            throw new AppException(ResultCode.NOT_FOUND.getMsg());
        }
        long startTime = System.currentTimeMillis();
        // 构造查询条件
        Criteria criteria = buildQueryCond(bean);
        log.info("WeiQingMenSecurityForAdminServiceImpl-list-SQL: {}", criteria.toString());
        Pagination pagination = sqfwFormsummaryNewService1.listPage(bean.getPageNo(), bean.getPageSize(), criteria);
        // 查询流程pdf
        List<Sqfw_formSummary_new> sqfwCustomForAdminCommonVOList = pagination.getList(Sqfw_formSummary_new.class);
        if (ObjectUtil.isNotEmpty(sqfwCustomForAdminCommonVOList)) {
            List<SqfwCustomForAdminCommonVO> finalCommonVOList = new ArrayList<SqfwCustomForAdminCommonVO>();
            Map<String, String> pdfUrlMap = CommonCheckUtils.getPdfUrlByFlowId(sqfwCustomForAdminCommonVOList);
            sqfwCustomForAdminCommonVOList.forEach(source -> {
                SqfwCustomForAdminCommonVO target = new SqfwCustomForAdminCommonVO();
                BeanUtil.copyProperties(source, target);
                target.setPdfUrl(pdfUrlMap.get(target.getSqfwFlowId()));
                if (Strings.isNotBlank(target.getCheckStatus())
                        && SqfwSummaryForAdminServiceImpl.TO_DO_CHECK_OUT.equals(target.getCheckStatus())
                        && null != target.getFillDate()) {
                    Date offsetDate = DateUtil.parse(CommonFormOfficeForAdminUtils.DATE_FORMAT.format(DateUtil.offsetDay(new Date(), -CommonFormOfficeForAdminUtils.TIME_OUT)));
                    Date thisFillDate = DateUtil.parse(CommonFormOfficeForAdminUtils.DATE_FORMAT.format(target.getFillDate()));
                    if (offsetDate.compareTo(thisFillDate) < 0) {
                        target.setCheckStatus(SqfwSummaryForAdminServiceImpl.CHECK_OUT);
                    }
                }
                finalCommonVOList.add(target);
            });
            pagination.setList(finalCommonVOList);
        }
        log.info("WeiQingMenSecurityForAdminServiceImpl-list-耗时: {}ms", System.currentTimeMillis() - startTime);
        return pagination;
    }

    @Override
    @Aop(TransAop.READ_COMMITTED)
    public int delete(String id) {
        Sqfw_formSummary_new sqfwFormSummaryNew = sqfwFormsummaryNewService1.fetch(id);
        if (sqfwFormSummaryNew == null) {
            throw new AppException(ResultCode.NULL_DATA_ERROR.getMsg());
        }
        batchDeleteDataNew(SecurityUtil.getUserId(), sqfwFormSummaryNew);
        return 0;
    }

    @Override
    public int batchDelete(List<String> ids) {
        return sqfwCommonForAdminService.batchDelete(ids);
    }

    @Override
    public int update(Sqfw_formSummary_new sqfwFormsummaryNew) {
        return 0;
    }

    @Override
    public List<GenerateExcelUrlVO> downloadExcel(List<ExcelCreateConfig> excelConfigList, SqfwCustomForAdminCommonVO bean) {
        if (StringUtils.isEmpty(bean.getType())) {
            throw new AppException(ResultCode.NOT_FOUND.getMsg());
        }
        // 如果formSummaryNewIdList为空，根据条件下载，否则根据勾选id下载
        if (ObjectUtil.isEmpty(bean.getFormSummaryNewIdList()) || bean.getFormSummaryNewIdList().size() <= 0) {
            Criteria criteria = buildQueryCond(bean);
            List<Sqfw_formSummary_new> summaryNewList = sqfwFormsummaryNewService1.query(criteria);
            if (summaryNewList.size() > 0) {
                bean.setFormSummaryNewIdList(sqfwFormsummaryNewService1.query(criteria).stream().map(Sqfw_formSummary_new::getId).collect(Collectors.toList()));
            } else {
                return new ArrayList<GenerateExcelUrlVO>();
            }
        }
        if (excelConfigList.get(0).getOnlyGenerateTemplateFlag()) {
            bean.setFormSummaryNewIdList(Collections.emptyList());
        }
        List<ResultOfExcelGenerator> excel = super.createExcelForAdmin(excelConfigList, bean.getFormSummaryNewIdList());
        List<GenerateExcelUrlVO> generateExcelUrlVOList = new ArrayList<GenerateExcelUrlVO>();
        if (ObjectUtil.isEmpty(excel)) {
            return generateExcelUrlVOList;
        }
        if (!excelConfigList.get(0).getCreateExcelFileFlag()) {
            if (CollectionUtil.isNotEmpty(excel) && excel.size() > 0) {
                excel.forEach(item -> {
                    if (item.getPassCreateConditionFlag() && !SafetyCheckEnum.SMS.getCode().equals(item.getFileIdentity())) {
                        GenerateExcelUrlVO generateExcelUrlVO = new GenerateExcelUrlVO();
                        generateExcelUrlVO.setFileIdentity(item.getFileIdentity());
                        generateExcelUrlVOList.add(generateExcelUrlVO);
                    }
                });
            }
            GenerateExcelUrlVO generateExcelUrlVO = new GenerateExcelUrlVO();
            generateExcelUrlVO.setFileIdentity(SafetyCheckEnum.SMS.getCode());
            generateExcelUrlVOList.add(generateExcelUrlVO);
        } else {
            GenerateExcelUrlVO generateExcelUrlVO = new GenerateExcelUrlVO();
            generateExcelUrlVO.setExcelUrl(excel.get(0).getExcelUrl());
            generateExcelUrlVOList.add(generateExcelUrlVO);
        }
        return generateExcelUrlVOList;
    }

    @Override
    public GenerateWordAndPdfUrlVO downloadPdf
            (List<ExcelCreateConfig> excelConfigList, SqfwCustomForAdminCommonVO bean) {
        return null;
    }

    @Override
    public List<GenerateExcelUrlVO> downloadPdfList(List<ExcelCreateConfig> excelConfigList, SqfwCustomForAdminCommonVO bean) {
        if (org.apache.commons.lang.StringUtils.isEmpty(bean.getType())) {
            throw new AppException(ResultCode.NOT_FOUND.getMsg());
        }
        // 如果formSummaryNewIdList为空，根据条件下载，否则根据勾选id下载
        if (ObjectUtil.isEmpty(bean.getFormSummaryNewIdList()) || bean.getFormSummaryNewIdList().size() <= 0) {
            Criteria criteria = buildQueryCond(bean);
            List<Sqfw_formSummary_new> summaryNewList = sqfwFormsummaryNewService1.query(criteria);
            if (summaryNewList.size() > 0) {
                bean.setFormSummaryNewIdList(summaryNewList.stream().map(Sqfw_formSummary_new::getId).collect(Collectors.toList()));
            } else {
                return new ArrayList<GenerateExcelUrlVO>();
            }
        }
        List<ResultOfExcelGenerator> resultPdf = safetyCheckPdfService.downPdfListToSummaryIds(excelConfigList, bean.getFormSummaryNewIdList());
        List<GenerateExcelUrlVO> generateExcelUrlVOList = new ArrayList<GenerateExcelUrlVO>();
        if (!excelConfigList.get(0).getCreateExcelFileFlag()) {
            if (CollectionUtil.isNotEmpty(resultPdf) && resultPdf.size() > 0) {
                resultPdf.forEach(item -> {
                    if (item.getPassCreateConditionFlag()) {
                        GenerateExcelUrlVO generateExcelUrlVO = new GenerateExcelUrlVO();
                        generateExcelUrlVO.setFileIdentity(item.getFileIdentity());
                        generateExcelUrlVOList.add(generateExcelUrlVO);
                    }
                });
            }
        } else {
            GenerateExcelUrlVO generateExcelUrlVO = new GenerateExcelUrlVO();
            generateExcelUrlVO.setExcelUrl(resultPdf.get(0).getExcelUrl());
            generateExcelUrlVOList.add(generateExcelUrlVO);
        }
        return generateExcelUrlVOList;
    }

    @Override
    public Criteria buildQueryCond(SqfwCustomForAdminCommonVO bean) {
        Criteria cri = Cnd.cri();
        SqlExpressionGroup criSql = cri.where();
        if (StringUtils.isEmpty(bean.getType())) {
            throw new AppException(ResultCode.NOT_FOUND.getMsg());
        }
        // 组装查询条件
        if (StringUtils.isNotBlank(bean.getPageOrderName()) && Strings.isNotBlank(bean.getPageOrderBy())) {
            if (bean.getPageOrderBy().equals(CommonConstants.ASC)) {
                cri.getOrderBy().asc(bean.getPageOrderName());
            }
            if (bean.getPageOrderBy().equals(CommonConstants.DESC)) {
                cri.getOrderBy().desc(bean.getPageOrderName());
            }
        } else {
            cri.getOrderBy().desc(Sqfw_formSummary_new::getFillDate);
        }
        // 类型
        criSql.andEquals(SqfwCustomForAdminCommonVO::getType, bean.getType());

        Sys_user sysUser = sysUserService.fetch(SecurityUtil.getUserId());
        if (ObjectUtils.isEmpty(sysUser)) {
            throw new AppException(ResultCode.USER_NOT_FOUND.getMsg());
        }
        // 区域5级检查
        CommonCheckUtils.checkAreaRange(criSql);
        // 省
        if (StringUtils.isNotBlank(bean.getProvince()) && !CommonCheckUtils.ZHISHU.equals(bean.getProvince())) {
            criSql.andEquals(SqfwCustomForAdminCommonVO::getProvince, bean.getProvince());
        }
        // 市
        if (StringUtils.isNotBlank(bean.getCity()) && !CommonCheckUtils.ZHISHU.equals(bean.getCity())) {
            criSql.andEquals(SqfwCustomForAdminCommonVO::getCity, bean.getCity());
        }
        // 区
        if (StringUtils.isNotBlank(bean.getDistrict()) && !CommonCheckUtils.ZHISHU.equals(bean.getDistrict())) {
            criSql.andEquals(SqfwCustomForAdminCommonVO::getDistrict, bean.getDistrict());
        }
        // 街道
        if (StringUtils.isNotBlank(bean.getCounty()) && !CommonCheckUtils.ZHISHU.equals(bean.getCounty())) {
            criSql.andEquals(SqfwCustomForAdminCommonVO::getCounty, bean.getCounty());
        }
        // 时间
        if (ObjectUtil.isNotEmpty(bean.getQueryStartTime()) && ObjectUtil.isNotEmpty(bean.getQueryEndTime())) {
            criSql.andBetween(Sqfw_formSummary_new::getFillDate,
                    communityStreetComponent.handleStartQueryTime(bean.getQueryStartTime()),
                    communityStreetComponent.handleEndQueryTime(bean.getQueryEndTime()));
        }
        // 辖区
        if (StringUtils.isNotBlank(bean.getCommunity())) {
            criSql.andLike(Sqfw_formSummary_new::getCommunity, bean.getCommunity());
        }
        // 全局搜索
        if (org.apache.commons.lang3.StringUtils.isNotEmpty(bean.getQueryAll())) {
            SqlExpressionGroup placeName = Cnd.exps(new Static("param_data->>'placeName' like '%" + bean.getQueryAll() + "%'"));
            SqlExpressionGroup operator = Cnd.exps(new Static("param_data->>'operator' like '%" + bean.getQueryAll() + "%'"));
            SqlExpressionGroup address = Cnd.exps(new Static("param_data->>'address' like '%" + bean.getQueryAll() + "%'"));
            SqlExpressionGroup attributesOfInspectionUnits = Cnd.exps(new Static("param_data->>'attributesOfInspectionUnits' like '%" + bean.getQueryAll() + "%'"));
            SqlExpressionGroup placeType = Cnd.exps(new Static("param_data->'placeType'->>'key' like '%" + bean.getQueryAll() + "%'"));
            SqlExpressionGroup operatorTelephone = Cnd.exps(new Static("param_data->>'operatorTelephone' like '%" + bean.getQueryAll() + "%'"));
            SqlExpressionGroup fireAndElectricityUsage = Cnd.exps(new Static("param_data->>'fireAndElectricityUsage' like '%" + bean.getQueryAll() + "%'"));
            SqlExpressionGroup community = Cnd.exps(new Static("community like '%" + bean.getQueryAll() + "%'"));
            SqlExpressionGroup createUserName = Cnd.exps(new Static("create_user_name like '%" + bean.getQueryAll() + "%'"));
            criSql.and(placeName.or(operator).or(address).or(attributesOfInspectionUnits).or(placeType).or(operatorTelephone).or(fireAndElectricityUsage).or(community).or(createUserName));
        }
        // 需要排除的数据
        criSql.andNotEquals(Sqfw_formSummary_new::getFillDate, CommonConstants.WASTE_CREATE_TIME);
        // 场所名称
        if (StringUtils.isNotBlank(bean.getPlaceName())) {
            criSql.andEquals("param_data->>'placeName'", bean.getPlaceName());
        }
        // 场所属性
        if (StringUtils.isNotBlank(bean.getAttributesOfInspectionUnits())) {
            criSql.andEquals("param_data->>'attributesOfInspectionUnits'", bean.getAttributesOfInspectionUnits());
        }
        // 场所类型
        if (StringUtils.isNotBlank(bean.getPlaceType())) {
            criSql.andEquals("param_data->'placeType'->>'key'", bean.getPlaceType());
        }
        // 联系人
        if (StringUtils.isNotBlank(bean.getOperator())) {
            criSql.andEquals("param_data->>'operator'", bean.getOperator());
        }
        // 经营者联系电话
        if (StringUtils.isNotEmpty(bean.getOperatorTelephone())) {
            criSql.andEquals("param_data->>'operatorTelephone'", bean.getOperatorTelephone());
        }
        // 联系地址
        if (StringUtils.isNotEmpty(bean.getAddress())) {
            criSql.andEquals("param_data->>'address'", bean.getAddress());
        }
        // 用户用火用电情况
        if (StringUtils.isNotEmpty(bean.getFireAndElectricityUsage())) {
            criSql.andEquals("param_data->>'fireAndElectricityUsage'", bean.getFireAndElectricityUsage());
        }
        // 是否是夜市摊点、游摊
        if (ObjectUtil.isNotEmpty(bean.getIsNightMarketStr())) {
            if ("0".equals(bean.getIsNightMarketStr())) {
                criSql.andNotEquals("param_data->>'attributesOfInspectionUnits'", "临摊、夜市摊");
            } else {
                criSql.andEquals("param_data->>'attributesOfInspectionUnits'", "临摊、夜市摊");
            }
        }
        // 风险类型
        if (StringUtils.isNotEmpty(bean.getRiskType())) {
            criSql.andEquals("param_data->>'riskType'", bean.getRiskType());
        }
        // 住人形式
        if (StringUtils.isNotEmpty(bean.getResidentialType())) {
            criSql.andEquals("param_data->'thereAreNoViolationsToLive'->>'key'", bean.getResidentialType());
        }
        // 检查人员
        if (StringUtils.isNotEmpty(bean.getCreateUserName())) {
            criSql.andEquals(Sqfw_formSummary_new::getCreateUserName, bean.getCreateUserName());
        }
        // 检查人员电话
        if (StringUtils.isNotEmpty(bean.getCreateUserPhone())) {
            criSql.andEquals(Sqfw_formSummary_new::getCreateUserPhone, bean.getCreateUserPhone());
        }
        // 检查状态(超时情况： 1-超时(未检查)， 2-未超时)
        if (Strings.isNotBlank(bean.getCheckStatus())) {
            if (CommonCheckUtils.CHECK_OUT.equals(bean.getCheckStatus())) {
                // 查询未超时数据，只查询30天内的未检查数据 + 已检查数据（（check_status != 2 且 fill_date>当前时间-30天））
                Date offsetDate = new Date();
                if ("安全排查".equals(bean.getType())) {
                    offsetDate = DateUtil.parse(CommonFormOfficeForAdminUtils.DATE_FORMAT.format(DateUtil.offsetDay(new Date(), -CommonFormOfficeForAdminUtils.TIME_OUT)));
                }
                SqlExpressionGroup notTimeOut = Cnd.exps(new Static("fill_date >= '" + offsetDate + "' AND check_status = '1'"));
                SqlExpressionGroup checked = Cnd.exps(new Static("check_status = '2'"));
                criSql.and(notTimeOut.or(checked));
            } else if (CommonCheckUtils.TO_DO_CHECK_OUT.equals(bean.getCheckStatus())) {
                // 查询超时数据，只查询30天前的数据（（check_status=1 且 fill_date<当前时间-30天））
                Date offsetDate = new Date();
                if ("安全排查".equals(bean.getType())) {
                    offsetDate = DateUtil.parse(CommonFormOfficeForAdminUtils.DATE_FORMAT.format(DateUtil.offsetDay(new Date(), -CommonFormOfficeForAdminUtils.TIME_OUT)));
                }
                criSql.and(Sqfw_formSummary_new::getFillDate, "<", offsetDate);
                criSql.andEquals(Sqfw_formSummary_new::getCheckStatus, bean.getCheckStatus());
            } else {
                criSql.andEquals(Sqfw_formSummary_new::getCheckStatus, bean.getCheckStatus());
            }
        }
        // 是否存在隐患
        if (ObjectUtil.isNotEmpty(bean.getIssueStatus())) {
            if ("1".equals(bean.getIssueStatus())) {
                criSql.andInStrList(Sqfw_formSummary_new::getIssueStatus, Arrays.asList("1", "2"));
            } else if ("0".equals(bean.getIssueStatus())) {
                criSql.andEquals(Sqfw_formSummary_new::getIssueStatus, "0");
            }
        }
        return cri;
    }

    @Override
    public List<CheckDataForAdminVO> checkDataInfoList(SqfwCustomForAdminCommonVO bean) {
        if (StringUtils.isEmpty(bean.getType())) {
            throw new AppException(ResultCode.NOT_FOUND.getMsg());
        }
        // 如果formSummaryNewIdList为空，根据条件下载，否则根据勾勾选id下载
        if (ObjectUtil.isEmpty(bean.getFormSummaryNewIdList()) || bean.getFormSummaryNewIdList().size() <= 0) {
            Criteria criteria = buildQueryCond(bean);
            List<Sqfw_formSummary_new> summaryNewList = sqfwFormsummaryNewService1.query(criteria);
            if (summaryNewList.size() > 0) {
                bean.setFormSummaryNewIdList(summaryNewList.stream().map(Sqfw_formSummary_new::getId).collect(Collectors.toList()));
            } else {
                return new ArrayList<CheckDataForAdminVO>();
            }
        }

        List<CheckDataForAdminVO> checkDataForAdminVOList = new ArrayList<CheckDataForAdminVO>();
        for (CheckDataForAdminVO item : checkDataForAdminVOList) {
            int a = sqfwFormsummaryNewService1.count(Cnd.where(Sqfw_formSummary_new::getId, "IN", bean.getFormSummaryNewIdList())
                    .and("param_data->>'institutionalCategory'", "=", EducationalInstitutionEnums.A.getName()));
            if (a > 0
                    && (item.getFileIdentity().equals(String.valueOf(EducationalInstitutionEnums.A.getCode()))
                    || item.getFileIdentity().equals(String.valueOf(EducationalInstitutionEnums.C.getCode())))) {
                item.setCreateConditionFlag(true);
            }
            int b = sqfwFormsummaryNewService1.count(Cnd.where(Sqfw_formSummary_new::getId, "IN", bean.getFormSummaryNewIdList())
                    .and("param_data->>'institutionalCategory'", "=", EducationalInstitutionEnums.B.getName()));
            if (b > 0
                    && (item.getFileIdentity().equals(String.valueOf(EducationalInstitutionEnums.B.getCode()))
                    || item.getFileIdentity().equals(String.valueOf(EducationalInstitutionEnums.D.getCode())))) {
                item.setCreateConditionFlag(true);
            }
        }
        return checkDataForAdminVOList;
    }

    @Override
    public void reGeneratePdf(String id) {
        safetyCheckPdfService.reCreatePdfAndMsg(id);
    }

    /**
     * 生成pdf合集
     *
     * @return
     */
    private String generatePdfColl(List<String> ids, String code) {
        String url = "";
        List<Sqfw_formSummary_new> formSummaryList = sqfwFormsummaryNewService1.query(Cnd.where(Sqfw_formSummary_new::getId, "IN", ids)
                .and("param_data->>'institutionalCategory'", "=", EducationalInstitutionEnums.getName(Integer.valueOf(code))));
        if (CollectionUtil.isNotEmpty(formSummaryList)) {
            List<String> summaryIdS = formSummaryList.stream().map(Sqfw_formSummary_new::getSqfwFlowId).collect(Collectors.toList());
            List<Sqfw_completeflow> completeflow = sqfwCompleteflowService.query(Cnd.where(Sqfw_completeflow::getId, "IN", summaryIdS)
                    .and(Sqfw_completeflow::getResourcePath, "!=", "creating")
                    .and(Sqfw_completeflow::getResourcePath, "!=", "error"));
            if (CollectionUtil.isNotEmpty(completeflow)) {
                List<String> pdfPathList = completeflow.stream().map(Sqfw_completeflow::getResourcePath).collect(Collectors.toList());
                url = CommonFormOfficeUtils.createConvergePdfAndUpload(pdfPathList, EducationalInstitutionEnums.getFileName(EducationalInstitutionEnums.getName(Integer.valueOf(code))));
            }
        }
        return url;
    }

    /**
     * 批量删除
     *
     * @param userId
     * @param data
     */
    private void batchDeleteDataNew(String userId, Sqfw_formSummary_new data) {
        //1 记录日志
        sysLogService.insertDelLog(userId, JSONObject.toJSONString(data), Sqfw_cenSusPaper.class.getAnnotation(Table.class).value(),
                "com.budwk.app.sqfw.services.customservice.WeiQingMenSecurityForAdminServiceImpl.batchDeleteDataNew",
                "com.budwk.app.sqfw.controllers.admin.WeiQingMenSecurityForAdminServiceImpl.batchDelete");
        // 2 删除数据
        sqfwCompleteflowService.deleteAndUpdateWO(data.getSqfwFlowId());
    }
}
